#include "Socket.hpp"
#include "Protocol.hpp"
#include <iostream>
using namespace SocketModel;

// ./tcpclient server_ip server_port
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        std::cout << "格式错误";
        return 0;
    }

    while (true)
    {
        int x, y;
        std::cout << "获取相应的x和y值";
        std::cin >> x >> y;
        std::cout << "获取相应的符号";
        char oper;
        std::cin >> oper;
        std::shared_ptr<Socket> clsocket = std::make_shared<TcpSocket>(); // 父类接口对接子类
        // 创建tcp套接字
        clsocket->SocketOrDie();
        InetAddr sever(argv[1], std::stoi(argv[2]));
        clsocket->SocketOrDie();

        // 完成业务逻辑
        Request data(x, y, oper);
        std::shared_ptr<Protocol> a = std::make_shared<Protocol>();
        Response res;
        a->GetResponse(clsocket, data, sever, res);

        // 读取结果
        res.ShowResult();
    }
}